package com.iot08.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.iot08.api.controller.base.BaseController;
import com.iot08.api.service.QuestionService;
import com.iot08.api.service.QuestionTitleService;
import com.iot08.api.service.TimingSwitchService;
import com.iot08.api.service.supplement.KafkaService;
import com.iot08.api.vo.request.TimingSwitchUpdateReqVo;
import com.iot08.api.vo.request.base.BaseAccountReqVO;
import com.iot08.common.constant.ConstKafka;
import com.iot08.common.entity.app.TimingSwitch;
import com.iot08.common.utils.response.ResponseMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 获取问题类别和热门问题
 * @author weichao 1299101858@qq.com
 * @version 1.0
 * @date 4/29/22 5:35 PM
 */
@Slf4j
@RestController
@RequestMapping("/getway/")
public class CategorysAndTitlesController extends BaseController {

    @Resource
    private QuestionService questionService;
    @Resource
    private QuestionTitleService questionTitleService;
    
    @GetMapping("categorys_and_titles")
    public ResponseMap getTimingSwitch (@Validated BaseAccountReqVO vo){
        JSONObject res = new JSONObject();
        List categorys = questionService.getDataList();
        Query query = new Query(Criteria.where("label").in("hot"));
        List titles = questionTitleService.getDataList(query);
        res.put("categorys", categorys);
        res.put("titles", titles);
        return ResponseMap.success(res);
    }

    @GetMapping("/titles/{categoryid}")
    public ResponseMap postTimingSwitch (@Validated BaseAccountReqVO vo, @PathVariable("categoryid") String categoryid){
        Query query = new Query(Criteria.where("categoryid").in(categoryid));
        List titles = questionTitleService.getDataList(query);
        JSONObject res = new JSONObject();
        res.put("titles", titles);
        return ResponseMap.success(res);
    }


}
